<template>
	<view class="generalization">
		<view class="tabbar flex_r_around">
			<view @click="onTab(1)" :id="tab==1 ? 'select' : ''">创意推广</view>
			<view @click="onTab(2)" :id="tab==2 ? 'select' : ''">广告余额</view>
			<view @click="onTab(3)" :id="tab==3 ? 'select' : ''">广告说明</view>
		</view>

		<view class="content1" v-if="tab == 1">
			<empty v-if="!popularizeList.length"></empty>
			<view class="list" v-for="(item,index) in popularizeList" :key="index">
				<view class="top flex_center">
					<view class="left">
						<image :src="item.content[0].image" mode="aspectFill"></image>
					</view>
					<view class="right">
						<view class="view hidden_3">{{item.profile}}</view>
						<view class="text hidden">{{item.content[0].content}}</view>
					</view>
				</view>

				<view class="bottom">
					<view class="text flex_r_between">
						<text>投放用户：{{item.message_num}}人</text>
						<text>已下单：{{item.order_num}}人</text>
						<view @click="toSet(item)">修改</view>
					</view>
					<view class="flex_r_around">
						<view class="bottom_btn" :style="`background: ${item.rec_show == 1 ? '#33A73B' : '#FD2A53'}`"
							@click="setPopularizeStatus(index)">
							{{
								item.rec_show == 0 ? '开始推广'
								: item.rec_show == 1 ? '停止推广'
								: item.rec_show == 2 ? '重新推广'
								: '开始推广'
							}}
						</view>
					</view>
				</view>

				<view class="status">
					{{
						item.rec_show == 1 ? '推广中'
						: item.rec_show == 2 ? '推广完成'
						: ''
					}}
				</view>
			</view>
		</view>


		<view class="poa_btn_box"  v-if="tab == 1">
			<view class="btn" @click="$util.toUrl('/pages/store/generalization/addAd')">+ 添加创意广告</view>
		</view>
		
		<walletVue ref="wallet" v-if="tab == 2"></walletVue>
		
		<illustrate ref="illustrate" v-if="tab == 3"></illustrate>
		

	</view>
</template>

<script>
	import walletVue from './wallet.vue';
	import illustrate from './illustrate.vue';
	import empty from '@/compentents/empty/empty.vue';
	
	export default {
		components: {
			walletVue,
			illustrate,
			empty
		},
		data() {
			return {
				tab: 1,

				// 创意推广列表
				popularizeList: [],
				popularizePage: 1,
				popularizeTotal: 0,
			}
		},
		
		methods: {
			onTab(e) {
				this.tab = e;
				if (e == 1) {
					this.refPopularizeList();
				}
			},
			
			refresh(){
				if(this.tab == 1){
					this.popularizePage = 1;
					this.$get('/popularize/getPopularizeList', {
						type: 6,
						page: this.popularizePage
					}).then(res => {
						this.list = [];
						this.popularizeTotal = res.data.total;
						this.popularizeList.push(...res.data.data);
						uni.stopPullDownRefresh();
					})
				}else {
					uni.stopPullDownRefresh();
				}
			},
			
			reachBottom(){
				if(this.tab == 1){
					if(this.popularizeTotal > this.popularizeList.length){
						this.popularizePage++;
						this.getPopularizeList();
					}
				}
			},

			getPopularizeList() {
				this.$get('/popularize/getPopularizeList', {
					type: 6,
					page: this.popularizePage
				}).then(res => {
					this.popularizeTotal = res.data.total;
					this.popularizeList.push(...res.data.data);
				})
			},

			refPopularizeList() {
				this.popularizePage = 1;
				this.$get('/popularize/getPopularizeList', {
					type: 6,
					page: this.popularizePage
				}).then(res => {
					this.popularizeList = [];
					this.popularizeTotal = res.data.total;
					this.popularizeList.push(...res.data.data);
				})
			},

			setPopularizeStatus(index) {
				// // 0=待推广，1=推广中，2=推广完成,3=推广停止
				var rec_show = 0;
				if (this.popularizeList[index].rec_show == 1) {
					rec_show = 3;
				} else {
					rec_show = 1;
				}

				this.$get('/popularize/setPopularizeStatus', {
					id: this.popularizeList[index].id,
					rec_show: rec_show,
				}).then(res => {
					this.$util.msg(res.msg);
					this.refPopularizeList();
				})
			},
			
			toSet(item){
				this.$util.toUrl(`/pages/store/generalization/addAd?data=${JSON.stringify(item)}`)
			},

		},

		created() {
			this.getPopularizeList();
		}
	}
</script>

<style lang="less" scoped>
	.generalization {
		padding: 0 24rpx 140rpx;
	}

	.tabbar {
		height: 64rpx;
		background: #FFFFFF;
		border-radius: 12rpx;

		view {
			font-size: 26rpx;
			color: #666666;
		}

		#select {
			font-weight: 500;
			font-size: 26rpx;
			color: #131313;
		}
	}

	.content1 {
		.list {
			border-radius: 24rpx;
			margin-top: 20rpx;
			overflow: hidden;

			position: relative;

			.status {
				font-weight: 500;
				font-size: 28rpx;
				color: #33A73B;
				position: absolute;
				right: 24rpx;
				top: 24rpx;
			}

			.top {
				padding: 24rpx;
				background: #FFF;

				.left {
					width: 144rpx;
					height: 200rpx;
					border-radius: 12rpx;

					image {
						width: 144rpx;
						height: 200rpx;
						border-radius: 12rpx;
					}
				}

				.right {
					width: 380rpx;
					margin-left: 14rpx;
					overflow: hidden;

					.view {
						font-weight: 500;
						font-size: 28rpx;
						color: #333333;
						line-height: 44rpx;
						margin-bottom: 10rpx;
						width: 380rpx;
					}

					.text {
						font-size: 26rpx;
						color: #666666;
						width: 380rpx;
					}
				}
			}

			.bottom {
				padding: 16rpx 24rpx 28rpx;
				background: #FFF6D9;

				.text {
					text {
						font-weight: 500;
						font-size: 26rpx;
						color: #A85900;
						line-height: 36rpx;
					}

					view {
						font-weight: 500;
						font-size: 26rpx;
						color: #FD2A53;
						line-height: 36rpx;
					}
				}

				.bottom_btn {
					width: 320rpx;
					height: 80rpx;
					background: #FD2A53;
					border-radius: 42rpx;
					font-weight: 500;
					font-size: 28rpx;
					color: #FFFFFF;
					line-height: 80rpx;
					text-align: center;
					margin-top: 24rpx;
				}
			}
		}
	}

	.poa_btn_box {
		padding: 0 24rpx;
		width: 100vw;
		position: fixed;
		bottom: 30rpx;
		left: 0;

		.btn {
			height: 100rpx;
			background: #FFF7F8;
			border-radius: 24rpx;
			border: 2rpx solid #FD2A53;
			font-weight: 500;
			font-size: 28rpx;
			color: #FD2A53;
			line-height: 100rpx;
			text-align: center;
		}
	}
</style>